package com.aw.guiguzi.adapter

import android.graphics.Typeface
import android.widget.TextView
import com.aw.guiguzi.R
import com.aw.guiguzi.util.DataUtil
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder

class NumSingleCheckRateAnalysisAdapter :
    BaseQuickAdapter<String, BaseViewHolder>(R.layout.adapter_num_single_check_rate_analysis) {
    private var mList: MutableList<String>? = ArrayList()

    init {
        if (mList == null) {
            mList = ArrayList()
        }
    }

    override fun convert(helper: BaseViewHolder, bean: String) {
        val tv_content = helper.getView<TextView>(R.id.tv_content)
        tv_content.setText(
            DataUtil.matcherSearchText(
                mContext.resources.getColor(R.color.teal_700),
                bean,
                arrayOf<String>("№."),
                true
            )
        )
        tv_content.setTypeface(
            null,
            if (helper.layoutPosition == 0) Typeface.BOLD else Typeface.NORMAL
        )
    }

    fun addAllData(dataList: MutableList<String>?) {
        mList = dataList
        setNewData(mList)
        notifyDataSetChanged()
    }

    fun clearData() {
        if (mList != null) {
            val startPosition = 0 //hasHeader is 1
            val preSize = mList!!.size
            if (preSize > 0) {
                mList!!.clear()
                notifyItemRangeRemoved(startPosition, preSize)
            }
        }
    }
}